%%%-------------------------------------------------------------------
%%% @author Rain
%%% @doc http服务处理模块
%%% @end
%%%-------------------------------------------------------------------
-module(http_handler).
-behavior(cowboy_handler).
-author("Rain").
-include("common.hrl").

%% API
-export([init/2]).


init(Req, State) ->
    try
        handle(Req, State)
    catch
        Class:Reason:Stack ->
            ?LOG_ERROR("try catch error： Class:~p Reason:~p~nStack:~p~n", [Class, Reason, Stack]),
            game_util_web:reply_success_json(#{<<"message">> => <<"server code error!!!">>}, Req, State)
    end.

path(Req) ->
    Path = cowboy_req:path(Req),
    filename:split(binary_to_list(Path)).

handle(Req, State) ->
    Resource = filename:join(path(Req)),
    do_handle(Resource, Req, State).

%%do_handle(Resource, #{method := <<"POST">>} = Req, State) ->
%%    handle_post(Resource, Req, State);
do_handle(_Resource, Req, State) ->
    game_util_web:reply_success_json(#{<<"message">> => <<"no handle">>}, Req, State).
